#include<iostream>
using namespace std;

int main() {
	int n, a[100][100], x;
	cin >> n;
	for (int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			cin >> a[i][j];
	cin >> x;
	int lone=0, rone=n-1, ltwo=0, rtwo=n-1;
    // 找行
	while(lone < rone) {
		int midone = (lone + rone) / 2;
		if (x < a[midone][0]) {
			rone = midone - 1;
		} else if (x > a[midone][n-1]) {
			lone = midone + 1;
		} else {
			lone = rone = midone;
			break;
		}
	}
	
    // 找列
	while(ltwo <= rtwo) {
		int midtwo = (ltwo + rtwo) / 2;
		if (x > a[lone][midtwo]) {
			ltwo = midtwo + 1;
		} else if (x < a[lone][midtwo]) {
			rtwo = midtwo - 1;
		} else {
			ltwo = midtwo;
			cout << lone+1 << " " << ltwo+1 << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
	return 0;
}